package com.gitee.feizns.explore.data_structure.tree.bs.easy;

/**
 * 617. 合并二叉树
 * @author feizns
 * @since 2020/1/4
 */
public class MergeTrees {

    public static TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        if ( t1 == null )
            return t2;
        else if ( t2 == null )
            return t1;

        t1.val += t2.val;
        t1.left = mergeTrees(t1.left, t2.left);
        t1.right = mergeTrees(t1.right, t2.right);
        return t1;
    }

    public static void main(String[] args) {
//        mergeTrees()
    }

//    public static TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
//        if ( t1 != null ) {
//            if ( t2 != null ) {
//                t1.val += t2.val;
//                t1.left = mergeTrees(t1.left, t2.left);
//                t1.right = mergeTrees(t1.right, t2.right);
//            } else {
//                t1.left = mergeTrees(t1.left, null);
//                t1.right = mergeTrees(t1.right, null);
//            }
//            return t1;
//        } else if ( t2 != null ) {
//            t2.left = mergeTrees(t2.left, null);
//            t2.right = mergeTrees(t2.right, null);
//            return t2;
//        }
//        return null;
//    }

}
